<template>
  <div class="register-page">
   <van-nav-bar title="账号注册" left-arrow @click-left="$router.push('/login')"/>
   <van-form @submit="onSubmit">
  <van-field
    v-model="username"
     name="username"
    placeholder="请填写账号"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
      name="password"
    placeholder="请填写密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button block type="info" native-type="submit" color='#21b97a'>提交</van-button>
  </div>
</van-form>
<router-link class=link to="/login">已注册？去登录</router-link>
  </div>
</template>

<script>
import { register } from '@/api/user'

export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      const data = await register(values)
      this.$toast.success('注册成功')
      console.log(data)
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
.van-nav-bar{
background-color:#21b97a;
}
/deep/ .van-ellipsis {
    color: #fff;
  }
/deep/  .van-nav-bar .van-icon {
    color: #fff;
  }
</style>
